/*
 * FindReplacePanel
 * Copyright (C) 2011, Aleksey Nikiforov
 *
 * This file is part of FindReplacePanel.
 *
 * FindReplacePanel is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * FindReplacePanel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package simplex3d.console.findreplace;

import java.awt.event.*;
import java.util.Map;
import javax.swing.*;


/**
 *
 * @author Aleksey Nikiforov (lex)
 */
 class FindComponent extends JPanel {

    /** Creates new form FindPanel */
    public FindComponent(Map<String, Action> optionsActions, Map<String, Action> findReplaceActions) {
        initComponents();

        javax.swing.GroupLayout layout = (javax.swing.GroupLayout) getLayout();
        OptionsComponent sp = new OptionsComponent(optionsActions);
        layout.replace(optionsPanel, sp);
        optionsPanel = sp;

        findNextButton.setAction(findReplaceActions.get(FindReplacePanel.CMD_FIND_NEXT));
        findPreviousButton.setAction(findReplaceActions.get(FindReplacePanel.CMD_FIND_PREVIOUS));
    }

    
    public JComboBox getFindComboBox() {
        return findComboBox;
    }


    public void addActionListener(ActionListener a) {
        ((OptionsComponent) optionsPanel).addActionListener(a);

        findNextButton.addActionListener(a);
        findPreviousButton.addActionListener(a);
    }

    public void removeActionListener(ActionListener a) {
        ((OptionsComponent) optionsPanel).removeActionListener(a);

        findNextButton.removeActionListener(a);
        findPreviousButton.removeActionListener(a);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        findLabel = new javax.swing.JLabel();
        findNextButton = new javax.swing.JButton();
        findPreviousButton = new javax.swing.JButton();
        optionsPanel = new javax.swing.JPanel();
        findComboBox = new javax.swing.JComboBox();

        setFocusCycleRoot(true);

        findLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("simplex3d/console/findreplace/Bundle"); // NOI18N
        findLabel.setText(bundle.getString("FindReplaceComponent.findLabel.text")); // NOI18N

        findNextButton.setMnemonic(java.util.ResourceBundle.getBundle("simplex3d/console/findreplace/Bundle").getString("FindReplaceComponent.findNextButton.mnemonic").charAt(0));
        findNextButton.setText(bundle.getString("FindReplaceComponent.findNextButton.text")); // NOI18N

        findPreviousButton.setMnemonic(java.util.ResourceBundle.getBundle("simplex3d/console/findreplace/Bundle").getString("FindReplaceComponent.findPreviousButton.mnemonic").charAt(0));
        findPreviousButton.setText(bundle.getString("FindReplaceComponent.findPreviousButton.text")); // NOI18N

        javax.swing.GroupLayout optionsPanelLayout = new javax.swing.GroupLayout(optionsPanel);
        optionsPanel.setLayout(optionsPanelLayout);
        optionsPanelLayout.setHorizontalGroup(
            optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 696, Short.MAX_VALUE)
        );
        optionsPanelLayout.setVerticalGroup(
            optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 63, Short.MAX_VALUE)
        );

        findComboBox.setEditable(true);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(findLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(findComboBox, 0, 487, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(findNextButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(findPreviousButton)
                .addContainerGap())
            .addComponent(optionsPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(findLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(findPreviousButton)
                    .addComponent(findNextButton)
                    .addComponent(findComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(optionsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox findComboBox;
    private javax.swing.JLabel findLabel;
    private javax.swing.JButton findNextButton;
    private javax.swing.JButton findPreviousButton;
    private javax.swing.JPanel optionsPanel;
    // End of variables declaration//GEN-END:variables

}
